//
//  MeunTabBarController.m
//  B
//
//  Created by lanou on 16/5/6.
//  Copyright © 2016年 裴启航. All rights reserved.
//

#import "MeunTabBarController.h"
#import "BaseNavigationController.h"

#import "MeViewController.h"
#import "NewsViewController.h"
#import "SportViewController.h"
#import "HealthViewController.h"

@interface MeunTabBarController ()<MeViewControllerDelegate>

@property (nonatomic, assign) BOOL isShakeCanChangeSkin;

@end

@implementation MeunTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self updateSkinModel];
    [self setupBasic];
    [self createViewController];
}

// 为四个tabBar创建视图
- (void)createViewController {
    HealthViewController *healthVC = [HealthViewController new];
    [self addChildViewController:healthVC withImage:[UIImage imageNamed:@"health_care@2x"] selectedImage:nil withTittle:@"健康"];
    SportViewController *sportVC = [SportViewController new];
    [self addChildViewController:sportVC withImage:[UIImage imageNamed:@"run@2x"] selectedImage:[UIImage imageNamed:@""] withTittle:@"运动"];
    NewsViewController *newsVC = [NewsViewController new];
    [self addChildViewController:newsVC withImage:[UIImage imageNamed:@"icon_news_default@2x"] selectedImage:nil withTittle:@"资讯"];
    MeViewController *meVC = [MeViewController new];
    [self addChildViewController:meVC withImage:[UIImage imageNamed:@"icon_mine_default@2x"] selectedImage:nil withTittle:@"个人"];
    meVC.delegate = self;
    

}
-(void)setupBasic {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateSkinModel) name:SkinModelDidChangedNotification object:nil];
    [UIApplication sharedApplication].applicationSupportsShakeToEdit = YES;
    [self becomeFirstResponder];
}
#pragma mark 更新皮肤模式 接到模式切换的通知后会调用此方法
-(void)updateSkinModel {
    NSString *currentSkinModel = [[NSUserDefaults standardUserDefaults] stringForKey:CurrentSkinModelKey];
    if ([currentSkinModel isEqualToString:NightSkinModelValue]) {
        self.tabBar.barTintColor = QHColor(34, 30, 33); // tabBar背景颜色
    } else {//日间模式
        self.tabBar.barTintColor = [UIColor whiteColor];
    }
}
- (void)addChildViewController:(UIViewController *)controller withImage:(UIImage *)image selectedImage:(UIImage *)selectImage withTittle:(NSString *)tittle{
    BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:controller];
    
    [nav.tabBarItem setImage:image];
    [nav.tabBarItem setSelectedImage:selectImage];
    //    nav.tabBarItem.title = tittle;
    //    controller.navigationItem.title = tittle;
    [[UITabBar appearance] setTintColor:[UIColor redColor]]; // 设置tabbaritem的点击后的背景颜色
    controller.title = tittle;//这句代码相当于上面两句代码
//    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];   // 设置tabbaritem的字体颜色
//    nav.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -3);
    [self addChildViewController:nav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
